<?php
namespace Admin\Model;
use Think\Model;
/**
 * 合伙人
 * 
 *
 */
class extendModel extends Model { 
    
    public function getNameAndIdByParent($where){
            $extend=D('extend');
            $extendInfo=$extend->field('storesys_user.nickname,storesys_extend.id,storesys_extend.level')->join('storesys_user on storesys_user.userid=storesys_extend.uid')->where($where)->select();
            return $extendInfo;
    }
    
    /**
     * 根据级别获取名称和id
     * @param unknown $where
     * @return unknown
     */
    public function getNameAndId($where){
        $extend=D('extend');
        $extendInfo=$extend->field('storesys_user.nickname,storesys_extend.id,storesys_extend.level')->join('storesys_user on storesys_user.userid=storesys_extend.uid')->where($where)->select();
        return $extendInfo;
    }
    
    /**
     * 获取分销商
     * @param     $where
     * @return  
     */
    public function getExtendInfo($where){
        $extend = D('extend');
        $extendInfo = $extend->where($where)->find();
        return $extendInfo;
    }
    
  
    /**
     * 根据条件查询总人数
     * @param   $where
     * @return  
     */
	public function getExtendCount($where){
	    $extend = D('extend');
	    $count = $extend
	    ->field('storesys_user.nickname,storesys_user.tel,storesys_user.isextend,storesys_user.createunixtime ,storesys_extend.id,storesys_extend.status,storesys_extend.createtime extendtime,storesys_extend.one_comm,storesys_extend.parentid')
	    ->join('storesys_user ON storesys_user.userid = storesys_extend.uid')
	    ->where($where)->count();
	    return $count;
	}
	/**
	 * 获取不同级别邀请人数
	 * @param unknown $where
	 */
	public function getNextBossCount($where){
	    $where['isextend']=1;
	    $extend = D('extend');
	    $count = $extend
	    ->join('storesys_user ON storesys_user.preveid = storesys_extend.id')
	    ->where($where)->count();
	    return $count;
	}
	/**
	 * 分页显示分销商
	 * @param   $where
	 * @param   $page
	 */
	public function getExtendBypage($where,$page){
	    $extend = D('extend');
	    $userExtendInfo = $extend
	    ->field('storesys_user.nickname,storesys_user.tel,storesys_user.isextend,storesys_user.createunixtime,storesys_extend.*')
	    ->join('storesys_user ON storesys_user.userid = storesys_extend.uid')
	    ->where($where)->page($page)->select();
	    return $userExtendInfo;
	}
	
	/**
	 * 查询分销以及用户
	 * @param unknown $where
	 */
	public function getExUserInfo($where){
	    $extend = D('extend');
	    $userExtendInfo = $extend
	    ->field('storesys_user.nickname,storesys_user.tel,storesys_extend.*')
	    ->join('storesys_user ON storesys_user.userid = storesys_extend.uid')
	    ->where($where)->find();
	    return $userExtendInfo;
	}
	/**
	 * 修改分销商
	 * @param   $where
	 * @param   $data
	 * @return  
	 */
	public function upExtend($where,$data){
	    $extend = D('extend');
	    $result = $extend->where($where)->save($data);
	    return $result;
	}
	
	
    /**
     * 删除分销商
     * @param   $where
     * @return  
     */
	public function delExtend($where){
	    $extend = D('extend');
	    $result = $extend->where($where)->delete();
	    return $result;
	}

	/**
	 * 添加分销
	 * @param unknown $data
	 * @return unknown
	 */
	public function addExtend($data){
	    $extend = D('extend');
	    $result = $extend->add($data);
	    return $result;
	}
}